import { Component, OnInit } from '@angular/core';
import { NzFormatBeforeDropEvent } from 'ng-zorro-antd/core';
import { of, Observable } from 'rxjs';
import { delay } from 'rxjs/operators';


@Component({
  selector: 'app-tree5',
  templateUrl: './tree5.component.html',
  styleUrls: ['./tree5.component.css']
})
export class Tree5Component implements OnInit {

  constructor() { }

  ngOnInit() {
  }

  nodes = [
    {
      title: '0-0',
      key: '100',
      expanded: true,
      children: [
        {
          title: '0-0-0',
          key: '1001',
          children: [{ title: '0-0-0-0', key: '10010', isLeaf: true }, { title: '0-0-0-1', key: '10011', isLeaf: true }]
        },
        {
          title: '0-0-1',
          key: '1002',
          children: [{ title: '0-0-1-0', key: '10020', isLeaf: true }]
        }
      ]
    }
  ];

  beforeDrop(arg: NzFormatBeforeDropEvent): Observable<boolean> {
    // if insert node into another node, wait 1s
    console.log(arg)
    console.log(arg.pos)
    // arg.pos === 0 代表移动了
    if (arg.pos === 0) { 
      console.log("等待1s")
      // 这一步没看懂 等待1s
      return of(true).pipe(delay(1000));
    } else {
      console.log("false")
      return of(false).pipe(delay(2000));
    }
  }

}
